```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Linux文件权限管理：正确设置文件和目录权限</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4.5rem;
            line-height: 0.65;
            margin: 0.1em 0.15em 0 0;
            color: #4f46e5;
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
        }
        .code-block {
            background-color: #1e293b;
            border-left: 4px solid #4f46e5;
        }
        .transition-all {
            transition: all 0.3s ease;
        }
        .permission-badge {
            background-color: #e0e7ff;
            color: #4f46e5;
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <div class="inline-block bg-indigo-500 bg-opacity-20 px-4 py-2 rounded-full mb-4">
                <span class="text-xs font-semibold tracking-wider uppercase"><i class="fas fa-lock mr-2"></i>Linux系统安全</span>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-6 leading-tight font-serif">Linux文件权限管理</h1>
            <p class="text-xl md:text-2xl font-light mb-8 max-w-3xl mx-auto opacity-90">正确设置文件和目录权限是保障系统安全与数据保密的关键实践</p>
            <div class="flex justify-center space-x-4">
                <a href="#basics" class="px-6 py-3 bg-white text-indigo-600 font-medium rounded-lg hover:bg-opacity-90 transition-all shadow-md">
                    <i class="fas fa-book-open mr-2"></i>学习基础
                </a>
                <a href="#examples" class="px-6 py-3 bg-indigo-800 text-white font-medium rounded-lg hover:bg-opacity-90 transition-all">
                    <i class="fas fa-code mr-2"></i>查看示例
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
        <!-- Introduction -->
        <section class="mb-20">
            <p class="text-lg leading-relaxed text-slate-700 drop-cap">在Linux操作系统中，文件和目录权限的正确设置是确保系统安全性和数据保密性的重要一环。不正确的权限设置可能导致敏感数据泄露、恶意操作和系统崩溃。本文将深入探讨如何正确设置文件和目录权限，以及通过实际代码示例来演示权限管理的方法。</p>
        </section>

        <!-- Permission Basics -->
        <section id="basics" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-key text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif">1. 权限基础</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">权限表示法</h3>
                    <p class="text-slate-700 mb-4">在Linux中，每个文件和目录都有三组权限：文件所有者、同组用户和其他用户。每组权限分为读(r)、写(w)和执行(x)。</p>
                    <div class="bg-slate-50 p-4 rounded-lg">
                        <p class="font-mono text-sm mb-2">-rw-r--r--</p>
                        <p class="text-sm text-slate-600">表示文件所有者有读写权限，同组用户和其他用户只有读权限。</p>
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">数字表示法</h3>
                    <p class="text-slate-700 mb-4">Linux使用数字来表示权限：</p>
                    <ul class="space-y-2">
                        <li class="flex items-center"><span class="permission-badge px-3 py-1 rounded-full text-sm font-medium mr-2">4</span> 读权限</li>
                        <li class="flex items-center"><span class="permission-badge px-3 py-1 rounded-full text-sm font-medium mr-2">2</span> 写权限</li>
                        <li class="flex items-center"><span class="permission-badge px-3 py-1 rounded-full text-sm font-medium mr-2">1</span> 执行权限</li>
                    </ul>
                    <p class="text-slate-700 mt-4">通过组合这些数字设置权限，如 <code class="bg-slate-100 px-2 py-1 rounded">chmod 644 file.txt</code></p>
                </div>
            </div>

            <!-- Mermaid Diagram -->
            <div class="bg-white rounded-xl shadow-md p-6 mb-8">
                <h3 class="text-xl font-semibold mb-6 text-indigo-600">权限结构可视化</h3>
                <div class="mermaid">
                    graph TD
                        A[文件权限] --> B[所有者权限]
                        A --> C[组权限]
                        A --> D[其他用户权限]
                        B --> E[读 r]
                        B --> F[写 w]
                        B --> G[执行 x]
                        C --> H[读 r]
                        C --> I[写 w]
                        C --> J[执行 x]
                        D --> K[读 r]
                        D --> L[写 w]
                        D --> M[执行 x]
                </div>
            </div>
        </section>

        <!-- Command Examples -->
        <section id="examples" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-terminal text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif">2. 常用命令示例</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-indigo-100 w-8 h-8 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-file-alt text-indigo-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-indigo-600">改变文件权限</h3>
                    </div>
                    <p class="text-slate-700 mb-4">使用<code class="bg-slate-100 px-2 py-1 rounded">chmod</code>命令改变文件和目录权限：</p>
                    <div class="code-block text-white p-4 rounded-lg mb-4 overflow-x-auto">
                        <pre><code># 添加执行权限
chmod +x script.sh

# 设置特定权限
chmod 755 directory/
chmod 644 file.txt</code></pre>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-indigo-100 w-8 h-8 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-users text-indigo-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-indigo-600">改变所有者和组</h3>
                    </div>
                    <p class="text-slate-700 mb-4">使用<code class="bg-slate-100 px-2 py-1 rounded">chown</code>和<code class="bg-slate-100 px-2 py-1 rounded">chgrp</code>改变所有者和所属组：</p>
                    <div class="code-block text-white p-4 rounded-lg mb-4 overflow-x-auto">
                        <pre><code># 改变文件所有者
chown user1 file.txt

# 同时改变所有者和组
chown user1:group1 file.txt

# 只改变所属组
chgrp group1 file.txt</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Special Permissions -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-shield-alt text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif">3. 特殊权限标志</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">SUID</h3>
                    <p class="text-slate-700 mb-4">设置SUID标志后，用户可以以文件所有者的权限执行可执行文件。</p>
                    <div class="code-block text-white p-4 rounded-lg">
                        <pre><code># 设置SUID
chmod u+s executable_file

# 数字表示法
chmod 4755 executable_file</code></pre>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">SGID</h3>
                    <p class="text-slate-700 mb-4">设置SGID标志后，在该目录下创建的文件会继承目录的所属组。</p>
                    <div class="code-block text-white p-4 rounded-lg">
                        <pre><code># 设置SGID
chmod g+s directory/

# 数字表示法
chmod 2755 directory/</code></pre>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">Sticky Bit</h3>
                    <p class="text-slate-700 mb-4">设置Sticky Bit后，只有文件所有者才能删除或重命名目录中的文件。</p>
                    <div class="code-block text-white p-4 rounded-lg">
                        <pre><code># 设置Sticky Bit
chmod +t directory/

# 数字表示法
chmod 1755 directory/</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Practical Scenarios -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-laptop-code text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif">4. 实际场景示例</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-indigo-100 w-8 h-8 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-server text-indigo-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-indigo-600">Web服务器文件权限</h3>
                    </div>
                    <p class="text-slate-700 mb-4">合理设置Web服务器文件权限：</p>
                    <div class="code-block text-white p-4 rounded-lg mb-4 overflow-x-auto">
                        <pre><code># 网页文件设置为只读
chmod 644 index.html style.css script.js

# 配置文件设置为管理员可写
chmod 640 config.ini

# 上传目录设置为可写
chmod 775 uploads/</code></pre>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-indigo-100 w-8 h-8 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-code text-indigo-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-indigo-600">脚本文件执行权限</h3>
                    </div>
                    <p class="text-slate-700 mb-4">赋予脚本文件执行权限：</p>
                    <div class="code-block text-white p-4 rounded-lg mb-4 overflow-x-auto">
                        <pre><code># 添加执行权限
chmod +x backup.sh

# 设置适当的权限
chmod 755 script.sh

# 执行脚本
./script.sh</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-check-circle text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif">5. 最佳实践</h2>
            </div>

            <div class="bg-white rounded-xl shadow-md p-8">
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="flex items-start">
                        <div class="bg-indigo-100 p-3 rounded-lg mr-4">
                            <i class="fas fa-lock text-indigo-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-lg font-semibold mb-2 text-indigo-600">最小权限原则</h3>
                            <p class="text-slate-700">为文件和目录分配最小必要权限，以减少潜在的风险。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <div class="bg-indigo-100 p-3 rounded-lg mr-4">
                            <i class="fas fa-users-cog text-indigo-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-lg font-semibold mb-2 text-indigo-600">适当的组管理</h3>
                            <p class="text-slate-700">将相关的用户放入同一组，并为该组分配适当的权限。</p>
                        </div>
                    </div>
                    
                    <div class="flex items-start">
                        <div class="bg-indigo-100 p-3 rounded-lg mr-4">
                            <i class="fas fa-ban text-indigo-600 text-xl"></i>
                        </div>
                        <div>
                            <h3 class="text-lg font-semibold mb-2 text-indigo-600">避免过度权限</h3>
                            <p class="text-slate-700">确保其他用户只能访问必要的文件。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Hands-on Example -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-hands-helping text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif">6. 深入实践：代码示例</h2>
            </div>

            <div class="bg-white rounded-xl shadow-md p-6 transition-all card-hover">
                <div class="code-block text-white p-4 rounded-lg overflow-x-auto">
                    <pre><code># 创建一个新的目录
mkdir my_directory

# 设置目录的权限为755，即rwxr-xr-x
chmod 755 my_directory

# 创建一个新的文件
touch my_file.txt

# 设置文件的权限为644，即rw-r--r--
chmod 644 my_file.txt

# 设置目录的SGID权限
chmod 2755 shared_directory/

# 设置脚本的SUID权限
chmod u+s important_script.sh

# 递归修改目录下所有文件的权限
chmod -R 755 web_assets/</code></pre>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-indigo-50 rounded-xl p-8 md:p-12 mb-20">
            <div class="flex items-center mb-6">
                <div class="w-12 h-12 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                    <i class="fas fa-brain text-indigo-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold font-serif">总结</h2>
            </div>
            <div class="prose max-w-none text-slate-700">
                <p>Linux文件权限的正确设置是系统安全的关键一环。通过数字表示法、常用命令示例和特殊权限标志，我们可以更好地管理文件和目录的权限。最佳实践是遵循最小权限原则，确保文件和目录只分配给需要访问它们的用户。</p>
                <p>掌握这些权限管理技巧，您将能够：</p>
                <ul class="list-disc pl-6 space-y-2">
                    <li>有效保护敏感数据不被未授权访问</li>
                    <li>防止意外或恶意的文件修改</li>
                    <li>建立安全的共享文件环境</li>
                    <li>维护系统稳定性和安全性</li>
                </ul>
                <p class="font-semibold mt-4">通过本文的指导，您可以更加自信地设置和管理Linux系统中的文件和目录权限。</p>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12 px-4 sm:px-6 lg:px-8">
        <div class="max-w-5xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">探索技术的无限可能</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition-colors">
                        <i class="fas fa-external-link-alt mr-2"></i>www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-sm text-gray-500">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            themeVariables: {
                primaryColor: '#4f46e5',
                primaryTextColor: '#ffffff',
                primaryBorderColor: '#4f46e5',
                lineColor: '#7c3aed',
                secondaryColor: '#7c3aed',
                tertiaryColor: '#4f46e5'
            }
        });
    </script>
</body>
</html>
```